package com.lagou.task02;

import java.util.Scanner;

public class exercise {

//    void  show(){
//        String[][] arr = new String[16][16];
//
//        for (int i = 0; i < 17; i++) {
//            if (i == 0) {
//                System.out.print(" ");
//            } else {1
//                System.out.printf("%x", i - 1);
//            }
//
//        }
//        System.out.println("");
//        for (int i = 0; i < 16; i++) {
//            System.out.printf("%x", i);
//            for (int j = 0; j < 16; j++) {
//                arr[i][j] = "+";
//                System.out.print("+");
//            }
//            System.out.println("");
//        }
//
//    }
      public void victory(){

      }

    public static void main(String[] args) {
        String[][] arr = new String[16][16];

        for (int i = 0; i < 17; i++) {
            if (i == 0) {
                System.out.print(" ");
            } else {
                System.out.printf("%x", i - 1);
            }

        }
        System.out.println("");
        for (int i = 0; i < 16; i++) {
            System.out.printf("%x", i);
            for (int j = 0; j < 16; j++) {
                arr[i][j] = "+";
                System.out.print("+");
            }
            System.out.println("");
        }
        int[] blackpoint = new int[2];
        int[] whitepoint = new int[2];
        Scanner input = new Scanner(System.in);
        boolean flag=true ;

       while (flag) {
            System.out.println("请黑方下棋");

            for (int i = 0; i < blackpoint.length; i++) {
                blackpoint[i] = input.nextInt();

                if (blackpoint[i] < 0 || blackpoint[i] > 16)

                    System.out.println("输入坐标有误!请重新输入");
                   continue;

            }

            if (arr[blackpoint[0]][blackpoint[1]] == "+") {
                arr[blackpoint[0]][blackpoint[1]] = "0";
            } else {
                System.out.println("该位置已有子，请重新输入!!!");
                continue;
            }
            for (int i = 0; i < 17; i++) {
                if (i == 0) {
                    System.out.print(" ");
                } else {
                    System.out.printf("%x", i - 1);
                }

            }
            System.out.println("");
            for (int i = 0; i < arr.length; i++) {
                System.out.printf("%x", i);
                for (int j = 0; j < arr[i].length; j++) {
                    System.out.print(arr[i][j]);
                }
                System.out.println("");
            }
            flag=false;
        }


       //白方下棋
        while (!flag) {
            System.out.println("请白方下棋");

            for (int i = 0; i < whitepoint.length; i++) {
                whitepoint[i] = input.nextInt();

                if (whitepoint[i] < 0 || whitepoint[i] > 16)

                    System.out.println("输入坐标有误!请重新输入");
                continue;

            }

            if (arr[whitepoint[0]][whitepoint[1]] == "+") {
                arr[whitepoint[0]][whitepoint[1]] = "1";
            } else {
                System.out.println("该位置已有子，请重新输入!!!");
                continue;
            }
            for (int i = 0; i < 17; i++) {
                if (i == 0) {
                    System.out.print(" ");
                } else {
                    System.out.printf("%x", i - 1);
                }

            }
            System.out.println("");
            for (int i = 0; i < arr.length; i++) {
                System.out.printf("%x", i);
                for (int j = 0; j < arr[i].length; j++) {
                    System.out.print(arr[i][j]);
                }
                System.out.println("");
            }
            flag=true;

        }


    }

}
